<?php
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="lt" lang="lt">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
        <title>Testinių duomenų importavimas</title>
    </head>
    <body bgcolor="#F0F0F0">
	<table border="0" bgcolor="white" align="center">
	<tr><td><a href="../"><img src="../GUI/Images/logo.png" alt="Paramos administravimo asistentas"/></a></td></tr>
	<tr><td><h2 align="center">Testiniai duomenys</h2></td></tr>
	<tr><td bgcolor="yellow">
		<b>Puslapis skirtas sistemos testavimui</b>.<br/>
		Norint importuoti duomenis, tereikia pasirinkti "Sql duomenys",<br/>
		ir jei norima, panaikinti esamus.
	</td></tr>
	<tr><td>
	    <?php
		include 'Init/database.php';
		$sqlList = include('sqlList.php');
		db_connect();

		if($_POST) {
		    if(isset($_POST['destroyh'])) {
			$sql = "DELETE FROM historical_quantities";
			mysql_query($sql);
			print "<label style='color:blue'>Istoriniai duomenys panaikinti.</label><br/>";
		    }
		    if(isset($_POST['destroyf'])) {
			$sql = "DELETE FROM  forecast_quantities";
			mysql_query($sql);
			print "<label style='color:blue'>Numatomi duomenys panaikinti.</label><br/>";
		    }
		    $file = mysql_real_escape_string($_POST['file']);
		    if(array_key_exists($file, $sqlList)) {
			$sql = file_get_contents($file);
			mysql_query($sql);
			print "<label style='color:green'>Duomenys įkelti: {$sqlList[$file]}</label><br/>";
		    }
		    print "</br>";
		}
	    ?>
	</td></tr>
	<tr><td>
	    <form action="sqlImporter.php" method="post">
		<label>Sql duomenys:</label>
		<select name="file">
		    <option></option>
		    <?php
                    $selected = 'selected="selected"';
		    foreach($sqlList as $file => $title) {
			print "<option $selected value='{$file}'>{$title}</option>";
                        $selected = '';
		    }
		    ?>
		</select><br/>
		<label>Ar naikinti visus senus istorinius duomenis:</label>
		<input type="checkbox" name="destroyh" value="1" checked="checked"/><br/>
<!--		<label>Ar naikinti visus numatomus duomenis:</label>
		<input type="checkbox" name="destroyf" value="1" checked/><br/>-->
		<input type="submit" value="Importuoti"/>
	    </form>
	</td></tr>
	</table>
    </body>
</html>
